package com.happy016;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration  //加入Spring配置
@EnableSwagger2 //开启Swagger
public class SwaggerConfig {

    private ApiInfo apiInfo() {
        //顾名思义
        return new ApiInfoBuilder()
                .title("Spring Boot中使用Swagger2构建RESTful APIs")
                .description("SpringBoot集成Swagger示例")
          /*      .termsOfServiceUrl("http://blog.happy016.com/")*/
                .contact(new Contact("Linyb","blog.happy106.com","lyb269@qq.com"))
                .version("1.0")
                .build();
    }

    @Bean
    public Docket createApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //扫描controller包下,如果某个不需要被扫描到,在具体API那边加上@ApiIgnore
                .apis(RequestHandlerSelectors.basePackage("com.happy016.controller"))
                .paths(PathSelectors.any())
                .build();
    }

}
